package com.quantstack.llcommonlibrary.dialog;

import android.content.Context;
import android.view.View;

import com.quantstack.llcommonlibrary.R;
import com.quantstack.llcommonlibrary.manager.DialogManager;
import com.quantstack.llcommonlibrary.manager.DialogView;

/**
 * @author wu_ming_zhi_bei
 * @date 2021/3/2 21:44
 * @Notes 权限弹框
 */
public class PermissionDialog {

    private DialogView permissionDialog;

    public PermissionDialog(Context context) {
        //初始化弹框
        permissionDialog = DialogManager.getInstance().initView(context, R.layout.dialog_permission);
        permissionDialog.findViewById(R.id.tv_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogManager.getInstance().hide(permissionDialog);
                if(onClickListener!=null){
                    onClickListener.onOk();
                }
            }
        });
        permissionDialog.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogManager.getInstance().hide(permissionDialog);
                if(onClickListener!=null){
                    onClickListener.onCancel();
                }
            }
        });
    }

    public void showDialog(){
        if(permissionDialog!=null){
            DialogManager.getInstance().show(permissionDialog);
        }
    }

    public void hideDialog(){
        if(permissionDialog!=null){
            DialogManager.getInstance().hide(permissionDialog);
        }
    }

    public OnClickListener onClickListener;

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener{
        void onOk();
        void onCancel();
    }
}
